
/**
 * Copyright (c) 2007, Ashish Lijhara
 * All rights reserved.
 *
 * MiniFrame.java
 *
 */

package crazy.java.Aetas;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.net.URL;
import javax.imageio.ImageIO;
import javax.swing.JPanel;
import java.util.Calendar;
import java.util.Timer;
import java.util.TimerTask;

/**
 *
 * @author  Ashish (Java Crazy)
 */

public class MiniBackGround extends JPanel{
    
    BufferedImage backImage;
    Calendar a;
    Calendar c;
    Timer timer = new Timer();
    TimerTask clockTask=new TimerTask() {
        public void run() {
            updateTime();
            repaint();
        }
    };
    
    /** Initializes the mini frame's background*/
    public MiniBackGround(){
        loadImage();
        a=Calendar.getInstance(java.util.TimeZone.getTimeZone("GMT+05:30"));
        timer.schedule(clockTask, 0, 60000);
        c =Calendar.getInstance(java.util.TimeZone.getTimeZone("GMT-06:00"));
        
    }
    
    /** Updates the Time of the object */
    
    private void updateTime() {
        c=Calendar.getInstance(java.util.TimeZone.getTimeZone("GMT-06:00"));
        a=Calendar.getInstance(java.util.TimeZone.getTimeZone("GMT+05:30"));
    }
    
    /**load the background image */
    public void loadImage(){
        try {
            File file = new File("res/minibg.png");
            backImage = ImageIO.read(new URL(file.toURI().toURL().toString()));
        } catch(IOException e) {
            e.printStackTrace();
        }
    }
    
    public void paintComponent(Graphics g){
        Graphics2D g2d=(Graphics2D)g;
        float width=getWidth();
        float height=getHeight();
        g2d.drawImage(backImage,0,0,null);
        g.setFont(FontUtil.getCompatiableFont("res/TRASHED.ttf",20f));
        g.setColor(new Color(42,50,68));
        g.drawString("AETAS",110,35);
        new GradientUtils(g2d,105,12,90,20,0,0,GradientUtils.RECT_GRADIENT);
        g.setFont(FontUtil.getCompatiableFont("res/TRASHED.ttf",15f));
        g.setColor(new Color(42,50,68));
        
        g.drawString("INDIA",20,80);
        g.drawString("CENTRAL AMERICA",20,160);
        
        
        String hr1;
        String min1;
        String sec1;
        g.setFont(FontUtil.getCompatiableFont("res/NEUROPOL.ttf",35f));
        int rhr1=a.get(Calendar.HOUR);
        if(rhr1==0) {
            rhr1=a.get(Calendar.HOUR_OF_DAY);
        }
        if(rhr1<=9){
            hr1="0"+Integer.toString(rhr1);
        } else{
            
            hr1=Integer.toString(rhr1);
        }
        
        if(a.get(Calendar.MINUTE)<=9){
            min1 = "0"+Integer.toString(a.get(Calendar.MINUTE));
        } else{
            min1 = Integer.toString(a.get(Calendar.MINUTE));
        }
        
        
        g.drawString(hr1+":"+min1,60,130);
        g.setFont(FontUtil.getCompatiableFont("res/TRASHED.ttf",12f));
        if(a.get(Calendar.AM_PM)==Calendar.AM){
            g.drawString("AM",230,130);
        } else{
            g.drawString("PM",230,130);
        }
        String hr2;
        String min2;
        String sec2;
        g.setFont(FontUtil.getCompatiableFont("res/NEUROPOL.ttf",35f));
        
        int hr=c.get(Calendar.HOUR);
        int min=c.get(Calendar.MINUTE);;
        if(hr==0) {
            hr=a.get(Calendar.HOUR_OF_DAY);
        }
        if(hr<=9){
            hr2="0"+Integer.toString(hr);
        } else{
            hr2=Integer.toString(hr);
        }
        if(min<=9){
            min2 = "0"+Integer.toString(min);
        } else{
            min2 = Integer.toString(min);
        }
        g.drawString(hr2+":"+min2,60,210);
        g.setFont(FontUtil.getCompatiableFont("res/TRASHED.ttf",12f));
        if(c.get(Calendar.AM_PM)==Calendar.AM){
            g.drawString("AM",230,210);
        } else{
            g.drawString("PM",230,210);
        }
        new GradientUtils(g2d,20,62,55,15,0,0,GradientUtils.RECT_GRADIENT);
        new GradientUtils(g2d,20,142,175,15,0,0,GradientUtils.RECT_GRADIENT);
        
    }
    
}

